package com.dgut.admin.controller;

import com.dgut.admin.param.ItemParam;
import com.dgut.admin.service.TypeService;
import com.dgut.common.utils.R;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @Author zyq
 * @Date 2022/4/10 9:57
 * @Description 回收物类别物品控制器
 * @Version 1.0
 **/
@RestController
@RequestMapping("/api/admin/type")
public class TypeController {

    private final TypeService typeService;
    public TypeController(TypeService typeService) {
        this.typeService = typeService;
    }

    /**
     * 回收物列表
     */
    @GetMapping("/item")
    public R listType(Integer pageNum, Integer pageSize, Integer categoryId, String name) {
        return R.ok().data(typeService.listType(pageNum, pageSize, categoryId, name));
    }

    /**
     * 回收物类别列表
     */
    @GetMapping("/category")
    public R listCategory(Integer pageNum, Integer pageSize) {
        return R.ok().data(typeService.listCategory(pageNum, pageSize));
    }

    /**
     * 回收物类别列表（不分页，用于筛选）
     */
    @GetMapping("/category/all")
    public R allCategory() {
        return R.ok().data(typeService.allCategory());
    }



    /**
     * 添加回收物
     */
    @PostMapping("/item")
    public R addItem(@RequestBody @Valid ItemParam param) {
        typeService.addItem(param);
        return R.ok();
    }


    /**
     * 添加回收物类别
     */
    @PostMapping("/category")
    public R addItem(@RequestParam String name) {
        typeService.addCategory(name);
        return R.ok();
    }

}
